import React, { useState, useEffect } from 'react'
import {Descriptions, Input, message} from "antd";
import {fetchRequest} from "../../../utils/Request";
import {url} from "../../../utils/url";
import {useRequest} from "@umijs/hooks";

interface requestParams {
    accDeviceCode: string
}

export default function EquipmentReissue() {

    const { Search } = Input;

    const onSearch = (value:string) => {
        if(value === ""){
            message.error("不允许输入空值");
        }
        else{
            deviceReissue.run({accDeviceCode:value});
        }
    }

    const deviceReissue = useRequest(deviceReissueRequest, {
        manual: true,
        loadingDelay: 200
    })

    //请求函数
    async function deviceReissueRequest(params: requestParams) {
        // console.log(params)
        try {
            const json = await fetchRequest(url.DEVICE_REISSUE, params)
            if (json.success) {
                message.success(json.data);
            } else {
                message.destroy();
                message.error(json.errorMsg);
            }
        } catch (error:any) {
            message.destroy();
            message.error(error.message);
        }
    }

    return (
        <div style={{ margin: '10px', padding: "14px"}}>
            <Descriptions title="设备重新下发说明" bordered column={{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }} layout="vertical">
                <Descriptions.Item label="操作场景">将设备中"推送不成功"的门禁进行重新推送</Descriptions.Item>
                <Descriptions.Item label="操作表名">access_card_dev_rel</Descriptions.Item>
                <Descriptions.Item label="操作说明">
                    将表中6、9、10状态改为4，put_count改为0
                </Descriptions.Item>
                <Descriptions.Item label="状态说明">4-待推送，6-推送失败，9-绑卡中，10-绑卡失败</Descriptions.Item>
            </Descriptions>
            <Search
                style={{ margin: '20px 0 0 0 ',width:'60%' }}
                placeholder="请输入设备编码"
                allowClear
                enterButton="重新下发"
                size="large"
                onSearch={onSearch}
                loading={deviceReissue.loading}
            />
        </div>

    )


}